<!--
 * @Descripttion: (订单主表/lay_order)
 * @Author: (admin)
 * @Date: (2024-10-10)
-->
<template>
  <div>
    <el-form :model="queryParams" label-position="right" inline ref="queryRef" v-show="showSearch" @submit.prevent>
      <el-form-item>
        <el-button icon="search" type="primary" @click="handleQuery">{{ $t('btn.search') }}</el-button>
        <el-button icon="refresh" @click="resetQuery">{{ $t('btn.reset') }}</el-button>
      </el-form-item>
    </el-form>
    <!-- 工具区域 -->
    <el-row :gutter="15" class="mb10">
      <el-col :span="1.5">
        <el-button type="primary" v-hasPermi="['layorder:add']" plain icon="plus" @click="handleAdd">
          {{ $t('btn.add') }}
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" :disabled="single" v-hasPermi="['layorder:edit']" plain icon="edit"
          @click="handleUpdate">
          {{ $t('btn.edit') }}
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" :disabled="multiple" v-hasPermi="['layorder:delete']" plain icon="delete"
          @click="handleDelete">
          {{ $t('btn.delete') }}
        </el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button type="warning" plain icon="download" @click="handleExport" v-hasPermi="['layorder:export']">
          {{ $t('btn.export') }}
        </el-button>
      </el-col> -->
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>

    <el-table :data="dataList" v-loading="loading" ref="table" border header-cell-class-name="el-table-header-cell"
      highlight-current-row @sort-change="sortChange" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50" align="center" />
      <!-- <el-table-column align="center" width="90">
        <template #default="scope">
          <el-button text @click="rowClick(scope.row)">{{ $t('btn.details') }}</el-button>
        </template>
</el-table-column> -->
      <el-table-column prop="orderNo" label="订单号" align="center" v-if="columns.showColumn('orderNo')" />
      <el-table-column prop="companyName" label="商家名称" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('companyName')" />
      <el-table-column prop="houseName" label="民宿名称" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('houseName')" />


      <el-table-column prop="roomName" label="房型名称" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('roomName')" />
      <el-table-column prop="specName" label="套餐名称" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('specName')" />
      <el-table-column prop="nickName" label="微信名称" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('nickName')" />
      <el-table-column prop="amountOrder" label="订单金额" width="85" align="center"
        v-if="columns.showColumn('amountOrder')" />
      <!-- <el-table-column prop="amountScore" label="积分金额" align="center" width="85"
        v-if="columns.showColumn('amountScore')" />
      <el-table-column prop="couponPrice" label="优惠劵金额" align="center" width="100"
        v-if="columns.showColumn('couponPrice')" />
      <el-table-column prop="amountDiscount" label="优惠金额" align="center" width="85"
        v-if="columns.showColumn('amountDiscount')" /> -->
      <!-- <el-table-column prop="score" label="积分" align="center" v-if="columns.showColumn('score')" /> -->
      <el-table-column prop="amountPay" label="实付金额" align="center" width="85" v-if="columns.showColumn('amountPay')" />
      <el-table-column label="预定日期" :show-overflow-tooltip="true" v-if="columns.showColumn('startDate')">
        <template #default="scope">
          {{ dayjs(scope.row.startDate).format("MM-DD") }}至{{ dayjs(scope.row.endDate).format("MM-DD") }}
        </template>
      </el-table-column>
      <el-table-column label="客户信息" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('customerName')" width="200" style="text-align: left">
        <template #default="scope">
          <p>姓名：{{ scope.row.customerName }}</p>
          <p>电话：{{ scope.row.customerPhone }}</p>
          <p>身份证：{{ scope.row.customerCard }}</p>
          <p>入住人数：{{ scope.row.customerNumber }}</p>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="customerNumber" label="客户人数" align="center" width="85"
        v-if="columns.showColumn('customerNumber')" />
      <el-table-column prop="customerCard" label="客户身份证" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('customerCard')" />
      <el-table-column prop="customerPhone" label="客户电话" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('customerPhone')" /> -->
      <!-- <el-table-column prop="customerRemark" label="客户备注" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('customerRemark')" /> -->
      <el-table-column prop="payTime" label="支付时间" :show-overflow-tooltip="true" v-if="columns.showColumn('payTime')" />



      <!-- <el-table-column prop="payNo" label="支付单号" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('payNo')" /> -->

      <!-- <el-table-column prop="payInfo" label="支付信息" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('payInfo')" /> -->
      <el-table-column prop="payName" label="支付名称" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('payName')" />
      <!-- <el-table-column prop="inTime" label="入住时间" :show-overflow-tooltip="true" v-if="columns.showColumn('inTime')" />
      <el-table-column prop="outTime" label="离店时间" :show-overflow-tooltip="true" v-if="columns.showColumn('outTime')" /> -->
      <!-- <el-table-column prop="tradeNo" label="TradeNo" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('tradeNo')" /> -->
      <!-- <el-table-column prop="refundNo" label="RefundNo" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('refundNo')" /> -->
      <!-- <el-table-column prop="userId" label="用户id" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('userId')" /> -->
      <!-- <el-table-column prop="id" label="Id" align="center" v-if="columns.showColumn('id')" /> -->
      <!-- <el-table-column prop="openid" label="openid" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('openid')" /> -->


      <!-- <el-table-column prop="endDate" label="止日期" :show-overflow-tooltip="true" v-if="columns.showColumn('endDate')" /> -->
      <!-- <el-table-column prop="inDays" label="几天" align="center" v-if="columns.showColumn('inDays')" /> -->
      <!-- <el-table-column prop="inNights" label="几晚" align="center" v-if="columns.showColumn('inNights')" /> -->

      <!-- <el-table-column prop="couponId" label="优惠劵" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('couponId')" /> -->
      <!-- <el-table-column prop="couponName" label="优惠劵名称" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('couponName')" /> -->
      <el-table-column prop="statusName" label="状态" align="center" width="80" v-if="columns.showColumn('status')">
        <!-- <template #default="scope">
          <dict-tag :options="options.orderStatusOptions" :value="scope.row.status" />
        </template> -->
      </el-table-column>
      <el-table-column label="操作" width="160">
        <template #default="scope">
          <el-button type="primary" size="small" title="" @click="handlePreview(scope.row)">订单详情</el-button>
          <!-- <el-button type="success" size="small" icon="edit" title="编辑" v-hasPermi="['layorder:edit']" @click="handleUpdate(scope.row)"></el-button> -->
          <!-- <el-button type="danger" size="small" icon="delete" title="删除" v-hasPermi="['layorder:delete']"
            @click="handleDelete(scope.row)"></el-button> -->
          <el-button type="warning" size="small" @click="ConfirmOrder(scope.row)">商家接单</el-button>
          <el-button type="success" size="small" icon="" title="确认入住" @click="OrderCheckIn(scope.row)">确认入住</el-button>
          <el-button type="danger" size="small" icon="" title="确认退款" @click="refundAmount(scope.row)">确认退款</el-button>
          <el-button type="primary" size="small" icon="" @click="LayOrder_Out(scope.row)">办理退房</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
      @pagination="getList" />

    <el-drawer v-model="drawer" size="50%" direction="rtl">
      <el-table :data="layOrderListList" header-row-class-name="text-navy">
        <el-table-column label="序号" type="index" width="80" />
        <el-table-column prop="id" label="Id" />
        <el-table-column prop="orderId" label="主表id" />
        <el-table-column prop="companyId" label="商家id" />
        <el-table-column prop="houseId" label="民宿id" />
        <el-table-column prop="roomId" label="房型id" />
        <el-table-column prop="specId" label="规格id" />
        <el-table-column prop="dates" label="日期" />
        <el-table-column prop="price" label="价格" />
        <el-table-column prop="priceDis" label="优惠价格">
          <template #default="scope">
            <dict-tag :options="options.priceDisOptions" :value="scope.row.priceDis" />
          </template>
        </el-table-column>
        <el-table-column prop="pricePay" label="实付价格" />
        <el-table-column prop="status" label="状态">
          <template #default="scope">
            <dict-tag :options="options.statusOptions" :value="scope.row.status" />
          </template>
        </el-table-column>
        <el-table-column prop="refundId" label="退款id" />
        <el-table-column prop="refundTime" label="退款时间" />
        <el-table-column prop="refundStatus" label="退款状态">
          <template #default="scope">
            <dict-tag :options="options.refundStatusOptions" :value="scope.row.refundStatus" />
          </template>
        </el-table-column>
      </el-table>
    </el-drawer>

    <el-dialog :title="title" :lock-scroll="false" v-model="open" :fullscreen="fullScreen">
      <el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
        <el-tabs type="border-card">
          <el-tab-pane label="基础信息">
            <el-row :gutter="20" class="orderInfo">
              <el-col :lg="8">
                <el-form-item label="订 单 号：" prop="orderNo">
                  {{ form.orderNo }}
                </el-form-item>
              </el-col>
              <el-col :lg="8">
                <el-form-item label="微信昵称：" prop="nickName">
                  {{ form.nickName }}
                </el-form-item>
              </el-col>

              <el-col :lg="8">
                <el-form-item label="商家名称：" prop="companyName">
                  {{ form.companyName }}
                </el-form-item>
              </el-col>

              <el-col :lg="8">
                <el-form-item label="民宿名称：" prop="houseName">
                  {{ form.houseName }}
                </el-form-item>
              </el-col>
              <el-col :lg="8">
                <el-form-item label="房型名称：" prop="roomName">
                  {{ form.roomName }}
                </el-form-item>
              </el-col>
              <el-col :lg="8">
                <el-form-item label="规格名称：" prop="specName">
                  {{ form.specName }}
                </el-form-item>
              </el-col>
              <el-col :lg="8">
                <el-form-item label="入住日期：" prop="startDate">
                  {{ dayjs(form.startDate).format("YYYY-MM-DD") }}
                  <!-- <el-date-picker
                v-model="form.startDate"
                type="datetime"
                placeholder="选择日期时间"
                value-format="YYYY-MM-DD HH:mm:ss">
              </el-date-picker> -->
                </el-form-item>
              </el-col>

              <el-col :lg="8">
                <el-form-item label="离店日期：" prop="endDate">
                  {{ dayjs(form.endDate).format("YYYY-MM-DD") }}
                  <!-- <el-date-picker
                v-model="form.endDate"
                type="datetime"
                placeholder="选择日期时间"
                value-format="YYYY-MM-DD HH:mm:ss">
              </el-date-picker> -->
                </el-form-item>
              </el-col>
              <el-col :lg="8">
                <el-form-item label="预定几晚：" prop="inNights">
                  {{ form.inNights }}晚
                </el-form-item>
              </el-col>

              <el-col :lg="8">
                <el-form-item label="入住时间：" prop="inTime">
                  {{ form.inTime }}
                  <!-- <el-date-picker
                v-model="form.inTime"
                type="datetime"
                placeholder="选择日期时间"
                value-format="YYYY-MM-DD HH:mm:ss">
              </el-date-picker> -->
                </el-form-item>
              </el-col>

              <el-col :lg="8">
                <el-form-item label="离店时间：" prop="outTime">
                  {{ form.outTime }}
                  <!-- <el-date-picker
                v-model="form.outTime"
                type="datetime"
                placeholder="选择日期时间"
                value-format="YYYY-MM-DD HH:mm:ss">
              </el-date-picker> -->
                </el-form-item>
              </el-col>

              <!--        
          <el-col :lg="12">
            <el-form-item label="TradeNo" prop="tradeNo">
              <el-input v-model="form.tradeNo" placeholder="请输入TradeNo" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="RefundNo" prop="refundNo">
              <el-input v-model="form.refundNo" placeholder="请输入RefundNo" />
            </el-form-item>
          </el-col> -->
            </el-row>
          </el-tab-pane>
          <el-tab-pane label="客户信息">
            <el-row :gutter="20" class="orderInfo">
              <el-col :lg="8">
                <el-form-item label="客户姓名：" prop="customerName">
                  {{ form.customerName }}
                </el-form-item>
              </el-col>
              <el-col :lg="6">
                <el-form-item label="客户电话：" prop="customerPhone">
                  {{ form.customerPhone }}
                </el-form-item>
              </el-col>
              <el-col :lg="6">
                <el-form-item label="客户身份证：" prop="customerCard">
                  {{ form.customerCard }}
                </el-form-item>
              </el-col>

              <el-col :lg="2">
                <el-form-item label="客户人数：" prop="customerNumber">
                  {{ form.customerNumber }}
                </el-form-item>
              </el-col>
              <el-col :lg="24">
                <el-form-item label="客户备注" prop="customerRemark">
                  {{ form.customerRemark }}
                </el-form-item>
              </el-col>

              <el-col :lg="12">
                <el-form-item label="支付名称" prop="payName">

                </el-form-item>
              </el-col>
              <el-col :lg="12">
                <el-form-item label="" style="float:right;font-weight:bold;" prop="payName">
                  {{ form.payName }}
                </el-form-item>
              </el-col>
              <el-col :lg="12">
                <el-form-item label="下单时间" prop="createTime">

                </el-form-item>
              </el-col>
              <el-col :lg="12">
                <el-form-item label="" style="float:right;font-weight:bold;" prop="createTime">
                  {{ form.createTime }}
                </el-form-item>
              </el-col>
              <el-col :lg="12">
                <el-form-item label="支付时间" prop="payTime">

                </el-form-item>
              </el-col>
              <el-col :lg="12">
                <el-form-item label="" style="float:right;font-weight:bold;" prop="payTime">
                  {{ form.payTime }}
                </el-form-item>
              </el-col>
              <el-col :lg="12">
                <el-form-item label="支付单号" prop="payNo">

                </el-form-item>
              </el-col>
              <el-col :lg="12">
                <el-form-item label="" style="float:right;font-weight:bold;" prop="payNo">
                  {{ form.payNo }}
                </el-form-item>
              </el-col>

            </el-row>
          </el-tab-pane>
        </el-tabs>
        <!-- <el-steps :active="form.status" align-center style="margin-top: 10px">
 
          <el-step title="用户已取消" description="用户已取消"></el-step>
          <el-step title="系统已取消" description="系统已取消"></el-step>
          <el-step title="订单已提交" description="订单已提交"></el-step>
          <el-step title="已支付" description="已支付"></el-step>
          <el-step title="待确认" description="已支付待确认"></el-step>
          <el-step title="商家已确认" description="商家已确认"></el-step>
          <el-step title="订单完成" description="订单完成"></el-step>
          <el-step title="已退单" description="已退单"></el-step>
          <el-step title="申请退款" description="申请退款"></el-step>
          <el-step title="已入住" description="已入住"></el-step>
        </el-steps> -->
        <el-divider content-position="center">订单明细表信息</el-divider>
        <!-- <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="Plus" @click="handleAddLayOrderList">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="Delete" @click="handleDeleteLayOrderList">删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="info" icon="FullScreen" @click="fullScreen = !fullScreen">{{ fullScreen ? '退出全屏' : '全屏' }}</el-button>
          </el-col>
        </el-row> -->
        <el-table :data="layOrderListList" :row-class-name="rowLayOrderListIndex" ref="LayOrderListRef">
          <!-- <el-table-column type="selection" width="40" align="center" /> -->
          @selection-change="handleLayOrderListSelectionChange"
          <el-table-column label="序号" align="center" prop="index" width="60" />

          <el-table-column label="日期" align="center" prop="dates">
            <template #default="scope">
              {{ dayjs(scope.row.dates).format("YYYY-MM-DD") }}
            </template>
            <!-- <template #default="scope">
              <el-date-picker clearable v-model="scope.row.dates" type="date" placeholder="选择日期时间"></el-date-picker>
            </template>-->
          </el-table-column>
          <el-table-column label="价格" align="center" prop="price">
            <!-- <template #default="scope">
              <el-input v-model="scope.row.price" placeholder="请输入价格" />
            </template> -->
          </el-table-column>
          <el-table-column label="优惠价格" align="center" prop="priceDis"></el-table-column>

          <el-table-column label="实付价格" align="center" prop="pricePay"></el-table-column>
          <!-- <el-table-column label="优惠价格" prop="priceDis">
            <template #default="scope">
              <el-select v-model="scope.row.priceDis" placeholder="请选择优惠价格">
                <el-option
                  v-for="item in options.priceDisOptions" 
                  :key="item.dictValue" 
                  :label="item.dictLabel" 
                  :value="item.dictValue"></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="实付价格" align="center" prop="pricePay">
            <template #default="scope">
              <el-input v-model="scope.row.pricePay" placeholder="请输入实付价格" />
            </template>
          </el-table-column> -->
          <el-table-column label="状态" prop="statusName">
            <!-- <template #default="scope">
              <el-select v-model="scope.row.status" placeholder="请选择状态">
                <el-option v-for="item in options.statusOptions" :key="item.dictValue" :label="item.dictLabel"
                  :value="item.dictValue"></el-option>
              </el-select>
            </template> -->
          </el-table-column>
          <!-- <el-table-column label="退款id" align="center" prop="refundId">
            <template #default="scope">
              <el-input v-model="scope.row.refundId" placeholder="请输入退款id" />
            </template>
          </el-table-column>
          <el-table-column label="退款时间" align="center" prop="refundTime">
            <template #default="scope">
              <el-date-picker clearable v-model="scope.row.refundTime" type="date" placeholder="选择日期时间"></el-date-picker>
            </template>
          </el-table-column>
          <el-table-column label="退款状态" prop="refundStatus">
            <template #default="scope">
              <el-select v-model="scope.row.refundStatus" placeholder="请选择退款状态">
                <el-option
                  v-for="item in options.refundStatusOptions" 
                  :key="item.dictValue" 
                  :label="item.dictLabel" 
                  :value="item.dictValue"></el-option>
              </el-select>
            </template>
          </el-table-column> -->
        </el-table>
        <el-row :gutter="20" class="orderInfo">

          <el-col :lg="12">
            <el-form-item label="订单金额" prop="amountOrder">

            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="" style="float:right;font-weight:bold;" rop="amountOrder">
              {{ form.amountOrder }}
            </el-form-item>
          </el-col>

          <el-col :lg="12">

            <el-form-item label="优惠劵金额" prop="couponPrice"></el-form-item>
          </el-col>
          <!-- <el-col :lg="12">
            <el-form-item label="优惠劵名称" prop="couponName">
              <el-input v-model="form.couponName" placeholder="请输入优惠劵名称" />
            </el-form-item>
          </el-col> -->

          <el-col :lg="12">
            <el-form-item label="" style="float:right;font-weight:bold;" prop="couponPrice">
              -{{ form.couponPrice }}
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="积分金额" prop="score">
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="" style="float:right;font-weight:bold;" prop="amountScore">
              -{{ form.amountScore }}
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="优惠总额" prop="amountDiscount">

            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="" style="float:right;font-weight:bold;" prop="amountDiscount">
              - {{ form.amountDiscount }}
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="实付金额" prop="amountPay">

            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="" style="float:right;font-weight:bold;color: red" prop="amountDiscount">
              {{ form.amountPay }}
            </el-form-item>
          </el-col>

          <!-- <el-col :lg="24">
            <el-form-item label="支付信息" prop="payInfo">
              <el-input type="textarea" v-model="form.payInfo" placeholder="请输入支付信息"/>
            </el-form-item>
          </el-col> -->
        </el-row>
      </el-form>
      <template #footer v-if="opertype != 3">
        <el-button text @click="cancel">{{ $t('btn.cancel') }}</el-button>
        <!-- <el-button type="primary" @click="submitForm">{{ $t('btn.submit') }}</el-button> -->
      </template>
    </el-dialog>

    <!-- 添加或修改政策对话框 -->
    <el-dialog :title="title" :lock-scroll="false" v-model="refundOpen">
      <el-form ref="formRef" :model="form" :rules="rules" label-width="100px">

        <el-row :gutter="20">

          <!-- <el-col :lg="10">
            <el-form-item label="退款类型" prop="name">
              <el-radio-group v-model="form.typeId">
                <el-radio :label="1">金额</el-radio>
                <el-radio :label="2">比例</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col> -->
          <el-col :lg="14">
            <el-form-item label="退款金额：" prop="name" style="color: red">
              <el-input v-model="form.inputRefundAmount" type="number" :min=0.01 :max=form.surplusAmount />
            </el-form-item>
          </el-col>
          <el-col :lg="5">
            <el-form-item label="可退金额" prop="name">
              <!-- <el-input v-model="form.amountPay" /> -->
              {{ form.surplusAmount }}元
            </el-form-item>
          </el-col>
          <!--<el-col :lg="6">
            <el-form-item label="已退金额" prop="name">
              <el-input v-model="form.refundAmount" />
            </el-form-item>
          </el-col>
          <el-col :lg="6">
            <el-form-item label="退款中" prop="name">
              <el-input v-model="form.refundingAmount" />
            </el-form-item>
          </el-col>
          <el-col :lg="6">
            <el-form-item label="可退金额" prop="name">
              <el-input v-model="form.surplusAmount" />
            </el-form-item>
          </el-col> -->
          <el-table :data="layOrderListList" :row-class-name="rowLayOrderListIndex"
            @selection-change="_handleSelectionChange" row-key="id">

            <el-table-column type="selection" width="40" :selectable="handleDisable" align="center" />

            <el-table-column label="序号" align="center" prop="index" width="60" />

            <el-table-column label="日期" align="center" prop="dates">
              <template #default="scope">
                {{ dayjs(scope.row.dates).format("YYYY-MM-DD") }}
              </template>
            </el-table-column>
            <el-table-column label="价格" align="center" prop="price">
            </el-table-column>
            <el-table-column label="优惠价格" align="center" prop="priceDis"></el-table-column>

            <el-table-column label="实付价格" align="center" prop="pricePay"></el-table-column>
            <el-table-column label="状态" prop="status">
              <template #default="scope">
                <span v-if="scope.row.status == 1">正常</span>
                <span v-if="scope.row.status == 2">退款</span>

              </template>
            </el-table-column>
          </el-table>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button text @click="refundcancel">{{ $t('btn.cancel') }}</el-button>
          <el-button type="primary" @click="refundsubmitForm">{{ $t('btn.submit') }}</el-button>
        </div>
      </template>
    </el-dialog>

  </div>
</template>

<script setup name="layorder">
import {
  listLayOrder,
  addLayOrder, delLayOrder,
  updateLayOrder, getLayOrder,
  LayOrderCheckIn, getOrderById, LayOrderAddRefund, LayOrderConfirm
  , LayOrderOut
}
  from '@/api/business/layorder.js'
import { dayjs, formatter } from 'element-plus';
import { DatetimeFormat } from 'vue-i18n';
import { max, min } from 'xe-utils';
const { proxy } = getCurrentInstance()
const ids = ref([])
const _ids = ref([])
const loading = ref(false)
const showSearch = ref(true)
const queryParams = reactive({
  pageNum: 1,
  pageSize: 10,
  sort: 'CreateTime',
  sortType: 'desc',
})
const columns = ref([
  { visible: true, align: 'center', type: '', prop: 'orderNo', label: '订单号' },
  { visible: false, align: 'center', type: '', prop: 'payTime', label: '支付时间', showOverflowTooltip: true },
  // { visible: true, align: 'center', type: '', prop: 'score', label: '积分' },
  { visible: true, align: 'center', type: '', prop: 'amountScore', label: '积分金额' },
  { visible: true, align: 'center', type: '', prop: 'amountPay', label: '实付金额' },
  { visible: true, align: 'center', type: '', prop: 'customerNumber', label: '客户人数' },
  { visible: true, align: 'center', type: '', prop: 'customerName', label: '客户姓名', showOverflowTooltip: true },
  { visible: true, align: 'center', type: '', prop: 'customerCard', label: '客户身份证', showOverflowTooltip: true },
  { visible: true, align: 'center', type: '', prop: 'customerPhone', label: '客户电话', showOverflowTooltip: true },
  { visible: false, align: 'center', type: '', prop: 'customerRemark', label: '客户备注', showOverflowTooltip: true },
  // { visible: false, align: 'center', type: 'dict', prop: 'status', label: '状态', showOverflowTooltip: true },
  { visible: true, align: 'center', type: '', prop: 'statusName', label: '状态名称', showOverflowTooltip: true },
  { visible: false, align: 'center', type: '', prop: 'payNo', label: '支付单号', showOverflowTooltip: true },
  { visible: true, align: 'center', type: '', prop: 'amountDiscount', label: '优惠金额' },
  { visible: false, align: 'center', type: '', prop: 'payName', label: '支付名称', showOverflowTooltip: true },
  { visible: false, align: 'center', type: '', prop: 'inTime', label: '入住时间', showOverflowTooltip: true },
  { visible: false, align: 'center', type: '', prop: 'outTime', label: '离店时间', showOverflowTooltip: true },
  { visible: false, align: 'center', type: '', prop: 'tradeNo', label: 'TradeNo', showOverflowTooltip: true },
  { visible: false, align: 'center', type: '', prop: 'refundNo', label: 'RefundNo', showOverflowTooltip: true },

  { visible: false, align: 'center', type: '', prop: 'companyName', label: '商家名称', showOverflowTooltip: true },

  { visible: true, align: 'center', type: '', prop: 'houseName', label: '民宿名称', showOverflowTooltip: true },
  { visible: true, align: 'center', type: '', prop: 'roomName', label: '房型名称', showOverflowTooltip: true },
  { visible: true, align: 'center', type: '', prop: 'specName', label: '规格名称', showOverflowTooltip: true },
  // { visible: false, align: 'center', type: '', prop: 'id', label: 'Id' },
  // { visible: false, align: 'center', type: '', prop: 'openid', label: 'openid', showOverflowTooltip: true },
  { visible: true, align: 'center', type: '', prop: 'nickName', label: '微信名称', showOverflowTooltip: true },
  { visible: true, align: 'center', type: '', prop: 'startDate', label: '预定日期', showOverflowTooltip: true },
  // { visible: false, align: 'center', type: '', prop: 'inDays', label: '几天' },
  { visible: true, align: 'center', type: '', prop: 'inNights', label: '几晚' },
  { visible: true, align: 'center', type: '', prop: 'amountOrder', label: '订单金额' },
  // { visible: false, align: 'center', type: '', prop: 'couponId', label: '优惠劵', showOverflowTooltip: true },
  // { visible: false, align: 'center', type: '', prop: 'couponName', label: '优惠劵名称', showOverflowTooltip: true },
  { visible: true, align: 'center', type: '', prop: 'couponPrice', label: '优惠劵金额' },
  //{ visible: false, prop: 'actions', label: '操作', type: 'slot', width: '160' }
])
const total = ref(0)
const dataList = ref([])
const dataRedundList = ref([])
const queryRef = ref()
const defaultTime = ref([new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)])


var dictParams = [
]


function getList() {
  loading.value = true
  listLayOrder(queryParams).then(res => {
    const { code, data } = res
    if (code == 200) {
      dataList.value = data.result
      total.value = data.totalNum
      loading.value = false
    }
  })
}

// 查询
function handleQuery() {
  queryParams.pageNum = 1
  getList()
}

// 重置查询操作
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}
// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1
  multiple.value = !selection.length;
}
// 自定义排序
function sortChange(column) {
  var sort = undefined
  var sortType = undefined

  if (column.prop != null && column.order != null) {
    sort = column.prop
    sortType = column.order

  }
  queryParams.sort = sort
  queryParams.sortType = sortType
  handleQuery()
}

/*************** form操作 ***************/
const formRef = ref()
const title = ref('')
// 操作类型 1、add 2、edit 3、view
const opertype = ref(0)
const open = ref(false)
const refundOpen = ref(false)
const state = reactive({
  single: true,
  multiple: true,
  form: {},
  rules: {
  },
  moneylist: [],
  options: {
    // 状态 选项列表 格式 eg:{ dictLabel: '标签', dictValue: '0'}
    statusOptions: [],
    orderStatusOptions: [
      { dictLabel: '待确认', dictValue: '1', listClass: 'info' },
      { dictLabel: '待入住', dictValue: '2', listClass: 'success' },
      { dictLabel: '已入住', dictValue: '3', listClass: 'info' },
      { dictLabel: '已完成', dictValue: '4', listClass: 'danger' },
      { dictLabel: '申请退款', dictValue: '5', listClass: 'warning' },
      { dictLabel: '退款中', dictValue: '6', listClass: 'danger' },
      { dictLabel: '部分退款', dictValue: '7', listClass: 'danger' },
      { dictLabel: '已取消', dictValue: '8', listClass: 'info' },
      { dictLabel: '已关闭', dictValue: '9', listClass: 'info' }

    ],
  }
})

const { form, rules, options, single, multiple } = toRefs(state)

// 关闭dialog
function cancel() {
  open.value = false
  reset()
}
function refundcancel() {
  refundOpen.value = false

}

// 重置表单
function reset() {
  form.value = {
    typeId: null,
    payTime: null,
    score: null,
    amountScore: null,
    amountPay: null,
    customerNumber: null,
    customerName: null,
    customerCard: null,
    customerPhone: null,
    customerRemark: null,
    status: null,
    statusName: null,
    payNo: null,
    amountDiscount: null,
    payInfo: null,
    payName: null,
    inTime: null,
    outTime: null,
    createTime: null,
    createBy: null,
    updateTime: null,
    updateBy: null,
    tradeNo: null,
    refundNo: null,
    userId: null,
    companyId: null,
    companyName: null,
    houseId: null,
    houseName: null,
    houseTitle: null,
    roomId: null,
    roomName: null,
    roomTitle: null,
    specId: null,
    specName: null,
    specTitle: null,
    id: null,
    openid: null,
    nickName: null,
    startDate: null,
    endDate: null,
    inDays: null,
    inNights: null,
    amountOrder: null,
    couponId: null,
    couponName: null,
    couponPrice: null,
    refundAmount: null,
    refundingAmount: null,
    surplusAmount: null,
    inputRefundAmount: null
  };
  layOrderListList.value = []
  proxy.resetForm("formRef")
}

/**
 * 查看
 * @param {*} row
 */
function handlePreview(row) {
  reset()
  const id = row.id
  getLayOrder(id).then((res) => {
    const { code, data } = res
    if (code == 200) {
      open.value = true
      title.value = '查看'
      opertype.value = 3
      form.value = {
        ...data,
      }
      layOrderListList.value = res.data.layOrderListNav
    }
  })
}
const OrderCheckInParams = reactive({
  id: null,
})
function OrderCheckIn(row) {

  const _id = row.id;
  OrderCheckInParams.id = _id
  proxy
    .$confirm('顾客【"' + row.customerName + '"】办理入住？', "警告", {
      confirmButtonText: proxy.$t('common.ok'),
      cancelButtonText: proxy.$t('common.cancel'),
      type: "warning",
    })
    .then(() => {
      LayOrderCheckIn(OrderCheckInParams).then((res) => {
        const { code, data } = res
        if (code == 200) {
          proxy.$modal.msgSuccess("办理入住成功")
        }
      })
    })

}
/**
 * 
 * @param row 商家确认或取消订单
 */
const ConfirmOrderParams = reactive({
  id: null,
  typeId: null,
})
function ConfirmOrder(row) {

  const _id = row.id;
  ConfirmOrderParams.id = _id
  proxy.$confirm('商家是否确认接单?', '提示', {
    confirmButtonText: '确定接单',
    cancelButtonText: '取消接单',
    type: 'warning',
    center: true,
    distinguishCancelAndClose: true,
  }).then(() => {
    ConfirmOrderParams.type = 1
    LayOrderConfirm(ConfirmOrderParams).then((res) => {
      const { code, data } = res
      if (code == 200) {
        proxy.$modal.msgSuccess("商家接单成功!")
      }
    })
  }).catch(function (e) {
    if (e == 'cancel') {
      // TODO 确认不通过执行逻辑
      ConfirmOrderParams.type = 2
      LayOrderConfirm(ConfirmOrderParams).then((res) => {
        const { code, data } = res
        if (code == 200) {
          proxy.$modal.msgSuccess("商家取消接单成功!")
        }
      })
    } else if (e == 'close') {
    }
  });
}

function refundAmount(row) {

  const _id = row.id;
  proxy.$confirm('顾客【"' + row.customerName + '"】是否退款？', "警告", {
    confirmButtonText: proxy.$t('common.ok'),
    cancelButtonText: proxy.$t('common.cancel'),
    type: "warning",
  })
    .then(() => {

      getOrderById(_id).then((res) => {
        const { code, data } = res
        if (code == 200) {

          refundOpen.value = true
          form.value = {
            ...data,
          }
          form.value.typeId = 1
          layOrderListList.value = data.layOrderListNav
        }
      })
    })

}

function LayOrder_Out(row) {
  const _id = row.id;
  proxy.$confirm('顾客【"' + row.customerName + '"】退房？', "警告", {
    confirmButtonText: proxy.$t('common.ok'),
    cancelButtonText: proxy.$t('common.cancel'),
    type: "warning",
  })
    .then(() => {
      LayOrderOut({ id: _id }).then((res) => {
        const { code, data } = res
        if (code == 200) {
          proxy.$modal.msgSuccess("操作成功!")
        }
      })
    })
}
// 添加按钮操作
function handleAdd() {
  reset();
  open.value = true
  title.value = '添加订单主表'
  opertype.value = 1
}
// 修改按钮操作
function handleUpdate(row) {
  reset()
  const id = row.id || ids.value
  getLayOrder(id).then((res) => {
    const { code, data } = res
    if (code == 200) {
      open.value = true
      title.value = '修改订单主表'
      opertype.value = 2

      form.value = {
        ...data,
      }
      layOrderListList.value = res.data.layOrderListNav
    }
  })
}

// 添加&修改 表单提交
function submitForm() {
  proxy.$refs["formRef"].validate((valid) => {
    if (valid) {

      form.value.layOrderListNav = layOrderListList.value
      if (form.value.id != undefined && opertype.value === 2) {
        updateLayOrder(form.value).then((res) => {
          proxy.$modal.msgSuccess("修改成功")
          open.value = false
          getList()
        })
      } else {
        addLayOrder(form.value).then((res) => {
          proxy.$modal.msgSuccess("新增成功")
          open.value = false
          getList()
        })
      }
    }
  })
}
function refundsubmitForm() {

  LayOrderAddRefund({ id: form.value.id, typeId: form.value.typeId, inputRefundAmount: form.value.inputRefundAmount, OrderListIds: _ids.value }).
    then((res) => {
      proxy.$modal.msgSuccess("提交成功")
      refundOpen.value = false
      getList()
    })
}
// 删除按钮操作
function handleDelete(row) {
  const Ids = row.id || ids.value

  proxy
    .$confirm('是否确认删除参数编号为"' + Ids + '"的数据项？', "警告", {
      confirmButtonText: proxy.$t('common.ok'),
      cancelButtonText: proxy.$t('common.cancel'),
      type: "warning",
    })
    .then(function () {
      return delLayOrder(Ids)
    })
    .then(() => {
      getList()
      proxy.$modal.msgSuccess("删除成功")
    })
}



// 导出按钮操作
function handleExport() {
  proxy
    .$confirm("是否确认导出订单主表数据项?", "警告", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    })
    .then(async () => {
      await proxy.downFile('/business/LayOrder/export', { ...queryParams })
    })
}

/*********************订单明细表子表信息*************************/
const layOrderListList = ref([])
const checkedLayOrderList = ref([])
const fullScreen = ref(false)
const drawer = ref(false)

/** 订单明细表序号 */
function rowLayOrderListIndex({ row, rowIndex }) {
  row.index = rowIndex + 1;
}

/** 订单明细表添加按钮操作 */
function handleAddLayOrderList() {
  let obj = {};
  //下面的代码自己设置默认值
  //obj.companyId = null;
  //obj.houseId = null;
  //obj.roomId = null;
  //obj.specId = null;
  //obj.dates = null;
  //obj.price = null;
  //obj.priceDis = null;
  //obj.pricePay = null;
  //obj.status = null;
  //obj.refundId = null;
  //obj.refundTime = null;
  //obj.refundStatus = null;
  layOrderListList.value.push(obj);
}

/** 复选框选中数据 */
function handleLayOrderListSelectionChange(selection) {
  checkedLayOrderList.value = selection.map(item => item.index)
}
/** 复选框选中数据 */
// 多选框选中数据
function _handleSelectionChange(selection) {
  _ids.value = selection.map((item) => item.id);
  state.moneylist = selection.map(
    (item) => item.pricePay
  );
  if (state.moneylist.length > 0) {
    form.value.inputRefundAmount = state.moneylist.reduce((pre, cur) => {
      return pre + cur;
    });
  } else {
    return (form.value.inputRefundAmount = null);
  }

}
function handleDisable(row) {
  return row.status == 1 ? true : false
}
/** 订单明细表删除按钮操作 */
function handleDeleteLayOrderList() {
  if (checkedLayOrderList.value.length == 0) {
    proxy.$modal.msgError('请先选择要删除的订单明细表数据')
  } else {
    const LayOrderLists = layOrderListList.value;
    const checkedLayOrderLists = checkedLayOrderList.value;
    layOrderListList.value = LayOrderLists.filter(function (item) {
      return checkedLayOrderLists.indexOf(item.index) == -1
    });
  }
}

/** 订单明细表详情 */
function rowClick(row) {
  const id = row.id || ids.value
  getLayOrder(id).then((res) => {
    const { code, data } = res
    if (code == 200) {
      drawer.value = true
      layOrderListList.value = data.layOrderListNav
    }
  })
}
handleQuery()
</script>
<style scoped>
.orderInfo div {
  height: 25px;
  line-height: 25px;
  margin-bottom: 0px !important;

}
</style>